import  axios from 'axios'
import  settings from '@/setting.js'
import  {getToken} from '@/utils/auth.js'

// create an axios instance
const request = axios.create({
    // url = base url + request url
    baseURL: settings.path,
    timeout: 30000 // request timeout
  })

// request interceptor
request.interceptors.request.use(
  config => {
    // do something before request is sent

    //if (store.getters.token) {
      // let each request carry token
      // ['X-Token'] is a custom headers key
      // please modify it according to the actual situation
      config.headers['authorization'] = "Bearer " +getToken()
    //}
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

export default  request 